<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>页面失活与定时器</title>
</head>
<body>
  <div class="text">
    当前页面状态：<span class="pageState"></span>
  </div>
  <script>
    let pageState = document.querySelector('.pageState');
    document.addEventListener('visibilitychange', function() {
      pageState.textContent = document.visibilityState
      console.log(document.visibilityState)
    })
  </script>
</body>
</html>